package com.guoxin.thread.stop;

/**
 * @author guoxin
 * @date 2019/6/28
 */
public class StopThread extends Thread {
    public boolean flag = true;

    @Override
    public synchronized void run() {
        while (flag) {
            try {
                wait();
            } catch (InterruptedException e) {
//                e.printStackTrace();
                stopThread();
            }
            System.out.println(Thread.currentThread().getName() + "--子线程");
        }
    }

    public void stopThread() {
        flag = false;
        System.out.println(getName() + "停止");
    }


}
